****APPENDIX TABLE C3****

cd "$main_dir/output/tables/appendix_c"

global basic 	sex marital religion edu

//--------------------------------------------------------
//Define relevant program
//--------------------------------------------------------

capture program drop standardize
program define standardize
	
	args depvar
	
	cap drop z*
	local varlist `depvar' wgrowth_rate_1 yob_ln_gdppc
	foreach var of local varlist {
		egen z`var' = std(`var') if e(sample)==1
}														

end

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs wgrowth_rate_1 yob_ln_gdppc)

fegen ccode_survey_year = group(ccode survey_year)
fegen subregion_yob = group(subregion yob) if yob!=-99
fegen ccode_age = group(ccode age) if age!=-99
fegen svy_survey_year = group(survey_year survey)

fegen age_educ_sex = group(age edu sex)

cap drop sample gallup_sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.
gen gallup_sample = 1 if born_country==1 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup"
replace gallup_sample = 1 if total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=. & survey=="Gallup" & (born_country!=0) & survey_year==2006

cap drop income_survey_sample
gen income_survey_sample = 1 if survey=="Gallup" | survey=="WVS" | survey=="EVS" | survey=="LITS" | survey=="Arabarometer" | survey=="Asiabarometer" | survey=="WJP"

gen quintile = .
replace quintile = 1 if inlist(income, 1, 2)
replace quintile = 2 if inlist(income, 3, 4)
replace quintile = 3 if inlist(income, 5, 6)	
replace quintile = 4 if inlist(income, 7, 8)	
replace quintile = 5 if inlist(income, 9, 10)
replace quintile = -99 if quintile==.

//--------------------------------------------------------
//Create Table C3
//--------------------------------------------------------

//Column 1
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if income_survey_sample==1, absorb(ccode svy_survey_year subregion_yob age $basic quintile employment_status urban) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if income_survey_sample==1, absorb(ccode svy_survey_year subregion_yob age $basic quintile employment_status urban) cluster(ccode)
outreg2 using table_c3.doc, replace dec(3) nocons addtext(Country FE, Yes, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, No, ///
														Country FE x Age FE, No, ///
														Economic Characteristics, Yes, ///
													    Survey, Harmonized) keep(zwgrowth_rate_1) 

//Column 2
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if income_survey_sample==1, absorb(ccode_survey_year svy_survey_year subregion_yob age $basic quintile employment_status urban) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if income_survey_sample==1, absorb(ccode_survey_year svy_survey_year subregion_yob age $basic quintile employment_status urban) cluster(ccode)
outreg2 using table_c3.doc, append dec(3) nocons addtext(Country FE, No, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, No, ///
														Economic Characteristics, Yes, ///
													    Survey, Harmonized) keep(zwgrowth_rate_1) 

//Column 3
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if income_survey_sample==1, absorb(ccode_survey_year ccode_age svy_survey_year subregion_yob $basic quintile employment_status urban) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if income_survey_sample==1, absorb(ccode_survey_year ccode_age svy_survey_year subregion_yob $basic quintile employment_status urban) cluster(ccode)
outreg2 using table_c3.doc, append dec(3) nocons addtext(Country FE, No, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, Yes, ///
														Economic Characteristics, Yes, ///
													    Survey, Harmonized) keep(zwgrowth_rate_1) 

//Column 4
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode svy_survey_year subregion_yob age $basic quintile employment_status urban) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode svy_survey_year subregion_yob age $basic quintile employment_status urban) cluster(ccode)
outreg2 using table_c3.doc, append dec(3) nocons addtext(Country FE, Yes, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, No, ///
														Country FE x Age FE, No, ///
														Economic Characteristics, Yes, ///
													    Survey, Gallup) keep(zwgrowth_rate_1) 	

//Column 5
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year subregion_yob age $basic quintile employment_status urban) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year subregion_yob age $basic quintile employment_status urban) cluster(ccode)
outreg2 using table_c3.doc, append dec(3) nocons addtext(Country FE, No, ///
														Survey Year FE x Survey FE, No, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, No, ///
														Economic Characteristics, Yes, ///
													    Survey, Gallup) keep(zwgrowth_rate_1) 															

//Column 6
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year ccode_age subregion_yob $basic quintile employment_status urban) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year ccode_age subregion_yob $basic quintile employment_status urban) cluster(ccode)
outreg2 using table_c3.doc, append dec(3) nocons addtext(Country FE, No, ///
														Survey Year FE x Survey FE, No, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, Yes, ///
														Economic Characteristics, Yes, ///
													    Survey, Gallup) keep(zwgrowth_rate_1) 
														
//--------------------------------------------------------
//Create Table C4
//--------------------------------------------------------

//Column 1
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode svy_survey_year subregion_yob age_educ_sex marital religion) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode svy_survey_year subregion_yob age_educ_sex marital religion) cluster(ccode)
outreg2 using table_c4.doc, replace dec(3) nocons addtext(Country FE, Yes, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, No, ///
														Country FE x Age FE, No, ///
														Age x Education x Sex Dummies, Yes, ///
													    Survey, Harmonized) keep(zwgrowth_rate_1) 

//Column 2
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode_survey_year svy_survey_year subregion_yob age_educ_sex marital religion) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode_survey_year svy_survey_year subregion_yob age_educ_sex marital religion) cluster(ccode)
outreg2 using table_c4.doc, append dec(3) nocons addtext(Country FE, No, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, No, ///
														Age x Education x Sex Dummies, Yes, ///
													    Survey, Harmonized) keep(zwgrowth_rate_1) 

//Column 3
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1, absorb(ccode_survey_year ccode_age svy_survey_year subregion_yob age_educ_sex marital religion) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if sample==1, absorb(ccode_survey_year ccode_age svy_survey_year subregion_yob age_educ_sex marital religion) cluster(ccode)
outreg2 using table_c4.doc, append dec(3) nocons addtext(Country FE, No, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, Yes, ///
														Age x Education x Sex Dummies, Yes, ///
													    Survey, Harmonized) keep(zwgrowth_rate_1) 

//Column 4
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode svy_survey_year subregion_yob age_educ_sex marital religion) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode svy_survey_year subregion_yob age_educ_sex marital religion) cluster(ccode)
outreg2 using table_c4.doc, append dec(3) nocons addtext(Country FE, Yes, ///
														Survey Year FE x Survey FE, Yes, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, No, ///
														Country FE x Age FE, No, ///
														Age x Education x Sex Dummies, Yes, ///
													    Survey, Gallup) keep(zwgrowth_rate_1) 	

//Column 5
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year subregion_yob age_educ_sex marital religion) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year subregion_yob age_educ_sex marital religion) cluster(ccode)
outreg2 using table_c4.doc, append dec(3) nocons addtext(Country FE, No, ///
														Survey Year FE x Survey FE, No, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, No, ///
														Age x Education x Sex Dummies, Yes, ///
													    Survey, Gallup) keep(zwgrowth_rate_1) 															

//Column 6
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year ccode_age subregion_yob age_educ_sex marital religion) cluster(ccode)
cap drop z*
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}													   
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if gallup_sample==1, absorb(ccode_survey_year ccode_age subregion_yob age_educ_sex marital religion) cluster(ccode)
outreg2 using table_c4.doc, append dec(3) nocons addtext(Country FE, No, ///
														Survey Year FE x Survey FE, No, ///
														Subcontinent FE x Cohort FE, Yes, ///
													    Country FE x Survey Year FE, Yes, ///
														Country FE x Age FE, Yes, ///
														Age x Education x Sex Dummies, Yes, ///
													    Survey, Gallup) keep(zwgrowth_rate_1) 														

